﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for User
/// </summary>
public class User : BaseBO {
	protected string firstName;
	protected string middleName;
	protected string lastName;
	protected string email;
	protected string password;
	protected bool enabled;

	protected string securityAnswer_Pet;

	protected List<Destination> destinations;
	protected List<Schedule> schedules;

	public string FirstName {
		get { return this.firstName; }
		set { this.firstName = value; }
	}

	public string MiddleName {
		get { return this.middleName; }
		set { this.middleName = value; }
	}

	public string LastName {
		get { return this.lastName; }
		set { this.lastName = value; }
	}

	public string SecurityAnswer_Pet {
		get { return this.securityAnswer_Pet; }
		set { this.securityAnswer_Pet = value; }
	}

	public string Email {
		get { return this.email; }
		set { this.email = value; }
	}

	public string Password {
		get { return this.password; }
		set { this.password = value; }
	}

	public bool Enabled {
		get { return this.enabled; }
		set { this.enabled = value; }
	}

	public List<Destination> Destinations {
		get { return this.destinations; }
		set { this.destinations = value; }
	}

	public List<Schedule> Schedules {
		get { return this.schedules; }
		set { this.schedules = value; }
	}

	public User() {
		this.destinations = new List<Destination>();
		this.schedules = new List<Schedule>();
	}

	public User(User user) {
		this.id = user.id;
		this.email = user.email;
		this.firstName = user.firstName;
		this.middleName = user.middleName;
		this.lastName = user.lastName;
		this.password = user.password;
		this.securityAnswer_Pet = user.securityAnswer_Pet;
		this.enabled = user.enabled;
		this.destinations = user.destinations;
		this.schedules = user.schedules;
	}

	/// <summary>
	/// Produces a list of schedules all having the same day of the week
	/// </summary>
	/// <param name="dayOfWeek"></param>
	/// <returns></returns>
	public Schedule getFirstSchedule(DayOfWeek dayOfWeek) {
		Schedule result = null;
		foreach (Schedule schedule in this.schedules) {
			if (schedule.DayOfWeek.Equals(dayOfWeek)) {
				result = schedule;
			}
		}
		return result;
	}

	public bool Equals(User user) {
		return this.id == user.id;
	}

	public override bool Equals(object obj) {
		return this.Equals((User) obj);
	}

	public override int GetHashCode() {
		return this.id;
	}

	public int CompareTo(User user) {
		int result = this.lastName.CompareTo(user.lastName);
		if (result == 0) {
			result = this.firstName.CompareTo(user.firstName);
			if (result == 0) {
				result = this.middleName.CompareTo(user.middleName);
				if (result == 0) {
					result = this.email.CompareTo(user.email);
				}
			}
		}
		return result;
	}
}
